<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script type="text/javascript">
	$(document).ready(function(){
		$("#searchBtn2").click(function(){
			location.href="${initParam.root}mypage/auth_searchDiaryByContent.do?content="+$("#searchDiary").val()+"&page=1";
		});
		$("#writeDiary").click(function(){
			location.href="${initParam.root}mypage/auth_writeDiaryForm.do";
		});
		$(".deleteDiary").click(function(){
			if(confirm("삭제하시겠습니까?")){
				location.href="${initParam.root}mypage/auth_deleteDiary.do?no="
				+$(this).parent().parent().children().eq(0).text()+
				"&page=${param.page}&filename="+$(this).siblings(":input[type=hidden]").val();
			}
		});
		$(".updateDiary").click(function(){
			//alert($(this).parent().parent().children().eq(0).text());
			if(confirm("수정하시겠습니까?")){
				location.href="${initParam.root}mypage/auth_updateDiaryForm.do?no="
						+$(this).parent().parent().children().eq(0).text()+
						"&page=${param.page}";
			}
		});
		/* $("#searchBtn").click(function(){
			location.href="${initParam.root}mypage/searchDiaryByContent.do?content="+$("#searchDiary").val()+"&page=${param.page}";
		}); */
		$("#myBtn").click(function(){
			location.href="${initParam.root}mypage/auth_myListPub.do";
		});
/*  		$(":input[name=searchDiary2]").keypress(function(event){
			if(event.keyCode == 13){
				$("#searchBtn2").click();
				return false;
			}
		}); */
		$("#searchKind").change(function(){
			if($(this).val()=="date"){
				//alert($(this).val());
				$("#searchDiary").datepicker({
		  			dateFormat:"yy-mm-dd",
		  			dayNamesMin:['일','월','화','수','목','금','토'],
		  			monthNames:['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월']
		  		});
				$("#searchBtn2").click(function(){
					location.href="${initParam.root}mypage/auth_searchDiaryByDate.do?date="+$("#searchDiary").val()+"&page=1";
				});
			}else if($(this).val()=="content"){
				$("#searchDiary").datepicker('destroy');
				$("#searchBtn2").click(function(){
					location.href="${initParam.root}mypage/auth_searchDiaryByContent.do?content="+$("#searchDiary").val()+"&page=1";
				});
			}
		});
	});
</script>
<h3>Diary</h3>
<img src="${initParam.root}img/diary_write.png" height="30" id="writeDiary">
<img src="${initParam.root}img/my.png" height="30" id="myBtn"><br>

<c:forEach var="dvo" items="${requestScope.lvo.list}">
	<table width="550" style="word-wrap: break-word; table-layout: fixed;">		
			<tr>
			    <td align="left" width="100">${dvo.no}</td>				
				<td align="left">${dvo.date}</td>
				<td align="right">
				<input type ="hidden" name ="filename" value="${dvo.newfilename}">
				<img src="${initParam.root}img/update.png" height="25"  class="updateDiary">
				<img src="${initParam.root}img/diary_delete.png" height="25"  class="deleteDiary">
				</td>
			</tr>
			
			<%-- jstl if로 bvo의 orgfilename이 null이 아니면 tr 영역을 보여준다 --%>
			<c:if test="${dvo.orgfilename!=null}">
			    <tr>
				<td colspan="3" align="right"><font size="2">
				첨부파일:
				<a href="${initParam.root}mypage/auth_diaryFileDownload.do?newfilename=${dvo.newfilename}&orgfilename=${dvo.orgfilename}"   >
					${dvo.orgfilename}
				</a>
				</font></td>
				</tr>
			 </c:if>
			
			<tr>
			<td colspan="3"><pre width="500" style="width:100%; height:80%; overflow:auto;">${dvo.content}</pre></td>
			</tr>
	</table>
	<hr width="550" align="left">
</c:forEach>
<br>
<p class="search" align="center">
<select id="searchKind">
	<option value="content">내용</option>
	<option value="date">작성일</option>
</select>
<input type="text" id="searchDiary" name="searchDiary2">
<input type="button" id="searchBtn2" value="검색">
</p>

<p class="paging" align="center">
   <c:set var="pb" value="${requestScope.lvo.pagingBean}"></c:set>
      
   <c:if test="${pb.previousPageGroup}">
      <a href="${initParam.root}mypage/auth_diaryList.do?page=${pb.startPageOfPageGroup-1}">◀</a>   
   </c:if>

   <c:forEach var="i" begin="${pb.startPageOfPageGroup}" end="${pb.endPageOfPageGroup}">
   <c:choose>
      <c:when test="${pb.nowPage!=i}">
         <a href="${initParam.root }mypage/auth_diaryList.do?page=${i}">${i}</a> 
      </c:when>
   <c:otherwise>
      <font style="color: red; font-size: 10.5pt;">${i}</font>
   </c:otherwise>
   </c:choose>
   </c:forEach>    
  
   <c:if test="${pb.nextPageGroup}">
      <a href="${initParam.root }mypage/auth_diaryList.do?page=${pb.endPageOfPageGroup+1}">▶</a>
   </c:if>
</p>
